//
//  RBMsgSystemDetailVC.m
//  zhongzhenglu
//
//  Created by XL on 2022/7/14.
//

#import "RBMsgSystemDetailVC.h"
#import "UIView+RBAdd.h"
#import <UIView+YYAdd.h>
#import "UIScrollView+RBAdd.h"
#import "RanTool.h"
#import <Masonry.h>
#import "RBDefine.h"
#import "RBThemeConfig.h"
#import <UIColor+YYAdd.h>
#import "RBMsgDetailResponse.h"
#import "UIViewController+RBAdd.h"

@interface RBMsgSystemDetailVC ()

@property(nonatomic, strong)UIScrollView *scrollView;
@property(nonatomic, strong) RBMsgDetailResponse *response;

@end

@implementation RBMsgSystemDetailVC

#pragma mark - Lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setup];
    [self getData];
}

#pragma mark - Private

- (void)setup
{
    self.title = @"系统消息";
    self.view.backgroundColor = UIColor.whiteColor;
}

- (void)fillData
{
    [self.scrollView rbSetContentWidth:kRBMainScreenWidth];
    [self.scrollView addView:({
        UIView *containerView = UIView.new;
        containerView.backgroundColor = UIColor.whiteColor;
        [containerView rbSetCornerRadius:Zoom(5)];
        
        UIView *titleL = ({
            UILabel *view = UILabel.new;
            view.numberOfLines = 0;
            view.textColor = [RBThemeConfig textBlackColor];
            view.font = [UIFont boldSystemFontOfSize:Zoom(18)];
            view.text = self.response.data.title;
            view;
        });
        [containerView view_addView:titleL withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(25) bottom:0 left:Zoom(17) right:Zoom(17) centerX:0];
        
        UIView *timeL = ({
            UILabel *view = UILabel.new;
            view.numberOfLines = 0;
            view.textColor = [RBThemeConfig textGrayColor];
            view.font = [UIFont systemFontOfSize:Zoom(13)];
            view.text = self.response.data.create_time;
            view;
        });
        [containerView view_addView:timeL withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(14) bottom:0 left:Zoom(17) right:Zoom(17) centerX:0];
        
        UIView *contentL = ({
            UILabel *view = UILabel.new;
            view.numberOfLines = 0;
            view.attributedText = [RanTool attributeStringMaker:^(NSMutableArray *maker) {
                [maker addAttributeStringWithFont:[UIFont systemFontOfSize:13] color:[RBThemeConfig textGrayColor] string:self.response.data.content lineSpacing:Zoom(7)];
            }];
            view;
        });
        [containerView view_addView:contentL withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(19) bottom:Zoom(29) left:Zoom(17) right:Zoom(17) centerX:0];
        
        containerView;
    }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(10) bottom:Zoom(10) left:Zoom(12) right:Zoom(12) centerX:0];
}

#pragma mark - Network

- (void)getData
{
    __weak typeof(self) weak_self = self;
    [self viewLoadDataWithParam:^(NSMutableDictionary *dicM) {
        dicM[@"xiaoxi_id"] = self.id;
    } path:@"han_xiaoxi_detail" post:YES log:YES responseClass:RBMsgDetailResponse.class desView:self.view showHud:YES showPlaceHolder:YES sucBlock:^(id data) {
        weak_self.response = data;
        [weak_self fillData];
    } failBlock:nil reloadBlock:^{
        [weak_self getData];
    }];
}

#pragma mark - Setter

#pragma mark - Getter

- (UIScrollView *)scrollView
{
    if (!_scrollView)
    {
        self.scrollView = ({
            UIScrollView *view = UIScrollView.new;
            view.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"];
            [self.view addSubview:view];
            [view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.edges.mas_equalTo(0);
            }];
            view;
        });
    }
    return _scrollView;
}

@end
